package com.atwisdom.star.common.util;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import java.util.UUID;

public class MbpUtil {
    public static <T> QueryWrapper<T> WrapperApply(String sql){
        QueryWrapper<T> queryWrapper=new QueryWrapper<>();
        queryWrapper.apply(sql);
        return queryWrapper;
    }
    public static <T> QueryWrapper<T> WrapperApply(String sql, QueryWrapper<T> queryWrapper ){
        queryWrapper.apply(sql);
        return queryWrapper;
    }

    public static <T> T mergeBean(T oldBean,T newBean,Class<T> clz){
        JSONObject oldObject=JsonUtil.toJSONObject(oldBean);
        JSONObject newObject=JsonUtil.toJSONObject(newBean);
        oldObject=JsonUtil.merge(oldObject,newObject);
        T bean= JSONObject.toJavaObject(oldObject, clz);
        return bean;
    }


    public static <T> T mergeBean(T oldBean,JSONObject newObject,Class<T> clz){
        JSONObject oldObject=JsonUtil.toJSONObject(oldBean);
        oldObject=JsonUtil.merge(oldObject,newObject);
        T bean= JSONObject.toJavaObject(oldObject, clz);
        return bean;
    }
}
